<template>
  <view>
    <!-- 轮播 -->
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true"
      indicator-color="white">
      <swiper-item v-for="(item) in swiperlist" :key="item.image_id">
        <navigator class="swiperitem" :url="'/subpages/goods-detail/goods-detail?goods_id='+item.goods_id">
          <image :src="item.image_src" mode=""></image>
        </navigator>
      </swiper-item>
    </swiper>
    <!-- nav -->
    <view class="navlist">
      <view class="navitem" v-for="(item,index) in navlist" key="index" @click="navClick(item)">
        <image :src="item.image_src"></image>
      </view>
    </view>
    <!-- floorimg -->
    <view class="floorlist">
      <view class="floor" v-for="(item,i) in floorlist" key="i">
        <!-- floortitle -->
        <image :src="item.floor_title.image_src" class="floortitle"></image>
        <view class="floorimg">
          <!-- 左边图片 -->
          <navigator class="leftimg" :url="item.product_list[0].url">
            <image :src="item.product_list[0].image_src" mode="widthFix"
              :style="{width: item.product_list[0].image_width + 'rpx'}"></image>
          </navigator>
          <!-- 右边图片 -->
          <view class="rightimg">
            <navigator v-for="(img,ind) in item.product_list" key="ind" :url="img.url" v-if="ind !== 0">
              <image :src="img.image_src" mode="widthFix" :style="{width: img.image_width + 'rpx'}">
              </image>
            </navigator>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        //轮播
        swiperlist: [],
        //标签栏
        navlist: [],
        //楼层数据
        floorlist: []
      };
    },
    onLoad() {
      this.getswiperList()
      this.getNavLIst()
      this.getfloorlist()
    },
    methods: {
      async getswiperList() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/swiperdata')
        if (res.meta.status !== 200) {
          return uni.$showMsg()
        } else {
          this.swiperlist = res.message
          uni.$showMsg('数据请求成功!')
        }
      },
      //标签列表
      async getNavLIst() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/catitems')
        if (res.meta.status !== 200) return uni.$showMsg()
        this.navlist = res.message
      },
      //nav点击
      navClick(item) {
        //判断点击了哪个nav
        if (item.name === "分类") {
          uni.switchTab({
            url: "/pages/cate/cate"
          })
        }
      },
      async getfloorlist() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/floordata')
        if (res.meta.status !== 200) return uni.$showMsg()
        //操作数组
        res.message.forEach((item, i) => {
          item.product_list.forEach((floor, ind) => {
            return floor.url = "/subpages/goods-list/goods-list?" + floor.navigator_url.split('?')[1]
          })
        })
        this.floorlist = res.message
      }
    }
  }
</script>

<style lang="scss">
  swiper {
    height: 330rpx;

    .swiperitem,
    image {
      width: 100%;
      height: 100%;
    }
  }

  .navlist {
    display: flex;
    justify-content: space-around;
    margin: 15rpx 0;

    .navitem {
      width: 128rpx;
      height: 140rpx;

      image {
        width: 100%;
        height: 100%;
      }
    }
  }

  .floortitle {
    height: 60rpx;
    width: 100%;
  }

  .floorimg {
    display: flex;
    padding: 0 10rpx;
    
    .rightimg {
      display: flex;
      justify-content: space-around;
      flex-wrap: wrap;
    }
  }
</style>
